#include "led.h"
#include "rtthread.h"

struct RGBLeds Led;

void RGBLeds_Init(void){
    // 获得led成员对应引脚地址
    Led.LED_R = rt_pin_get("PE.1");
    Led.LED_G = rt_pin_get("PE.4");
    Led.LED_B = rt_pin_get("PA.1");
    // 设置引脚为输出方式
    rt_pin_mode(Led.LED_R, PIN_MODE_OUTPUT);
    rt_pin_mode(Led.LED_G, PIN_MODE_OUTPUT);
    rt_pin_mode(Led.LED_B, PIN_MODE_OUTPUT);
}


void RGBLeds_Red(rt_bool_t status){
    if (status) {
        rt_pin_write(Led.LED_R, PIN_LOW);
    }else {
        rt_pin_write(Led.LED_R, PIN_HIGH);
    }
    rt_pin_write(Led.LED_G, PIN_HIGH);
    rt_pin_write(Led.LED_B, PIN_HIGH);
}

void RGBLeds_Blue(rt_bool_t status){
    if (status) {
        rt_pin_write(Led.LED_B, PIN_LOW);
    }else {
        rt_pin_write(Led.LED_B, PIN_HIGH);
    }
    rt_pin_write(Led.LED_G, PIN_HIGH);
    rt_pin_write(Led.LED_R, PIN_HIGH);
}

void RGBLeds_Green(rt_bool_t status){
    if (status) {
        rt_pin_write(Led.LED_G, PIN_LOW);
    }else {
        rt_pin_write(Led.LED_G, PIN_HIGH);
    }
    rt_pin_write(Led.LED_R, PIN_HIGH);
    rt_pin_write(Led.LED_B, PIN_HIGH);
}

void RunningWaterLamp(void){
    RGBLeds_Red(ON);
    rt_thread_mdelay(500);
    RGBLeds_Red(OFF);
    RGBLeds_Blue(ON);
    rt_thread_mdelay(500);
    RGBLeds_Blue(OFF);
    RGBLeds_Green(ON);
    rt_thread_mdelay(500);
    RGBLeds_Green(OFF);
    RGBLeds_Red(ON);
    RGBLeds_Blue(ON);
    rt_thread_mdelay(500);
    RGBLeds_Red(OFF);
    RGBLeds_Blue(OFF);
    RGBLeds_Red(ON);
    RGBLeds_Blue(ON);
    RGBLeds_Green(ON);
    rt_thread_mdelay(500);
    RGBLeds_Red(OFF);
    RGBLeds_Blue(OFF);
    RGBLeds_Green(OFF);
    rt_thread_mdelay(500);
}